/**
 * @program: clms-second
 * @description:
 * @author: mitu_echo
 * @create: 2021-08-07 11:54
 **/

package com.second.weixinpay.service.impl;

import com.second.common.pojo.R;
import com.second.weixinpay.pojo.util.WeiXinPayUtil;
import com.second.weixinpay.service.WeiXinPayService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Service
public class WeiXinPayServiceImpl implements WeiXinPayService {

    @Override
    public R getCode() {
        String uuid = UUID.randomUUID().toString();
        String[] idarr = uuid.toString().split("-");
        StringBuffer orderNo = new StringBuffer();
        for (String no : idarr) {
            orderNo.append(no);
        }
        String code = WeiXinPayUtil.getCode(orderNo.toString());
        if (code != null) {
            List list = new ArrayList();
            list.add(code);
            list.add(orderNo);
            return R.success().putListData(list);
        }
        return R.error();
    }

    @Override
    public R getPayStatus(String orderNo) {

        Boolean payStatus = WeiXinPayUtil.getPayStatus(orderNo);
        if (payStatus) {
            // 支付成功
            return R.success();
        }
        return R.error();
    }
}
